home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 23 / Commodore_Free_Issue_23_2008_Commodore_Computer_Club.d64 / t.b guide 8.1 < prev    next >
Text File  |  2023-02-26  |  12KB  |  394 lines

  1. u
  2.  
  3. In the Beginning Chapter 8 Section 1
  4. -------------------------
  5. \Lord Ronin from Q-Link\
  6.  
  7. Personal part here, I did say before
  8. that this is a personal look on the
  9. C=. One of the first programmes that I
  10. ever typed in was a game very similar
  11. to this upcoming guessing game. What I
  12. did was mess about with the colours
  13. and the word print statements.
  14. According to some of the big time
  15. programmers on the different Internet
  16. C= lists. that makes me a none
  17. programmer. Agree or not, the point of
  18. this story is that you should feel
  19. free to play with the programme, you
  20. are not going to hurt the C=.
  21.  
  22. 1 REM NUMBER GUESSING GAME
  23. 2 ?"(SHIFTED CLEAR HOME)"
  24. 5 INPUT"ENTER UPPERLIMIT FOR GUESS";LI
  25. 10 NM=INT(LI*RND(1))+1
  26. 15 CN=0
  27. 20 ?"I'VE GOT THE NUMBER.":?
  28. 30 ?"WHAT'S YOUR GUESS";GU
  29. 35 CN=CN+1
  30. 40 IFGU>NMTHEN?"MY NUMBER IS
  31.     LOWER":?:GOTO30
  32. 50 IFGU<NMTHEN?"MY NUNMBER IS
  33.     HIGHER:?:GOTO30
  34. 60 ?"GREAT! YOU GOT MY NUMBER"
  35. 65 ?"IN ONLY ";CN;"GUESSES.":?
  36. 70 ?"DO YOU WANT TO TRY ANOTHER(Y/N)";
  37. 80 GETAN$:IFAN$=""THEN80
  38. 90 IFAN$="Y"THEN2
  39. 100 IFAN$<>"N"THEN70
  40. 110 END
  41.  
  42. Oh wow man that is a mess of
  43. meaningless drenn; lets try to take it
  44. apart. First thought some information
  45. about the use of spaces. The Commodore
  46. book shows the listing with spaces
  47. separating the individual parts or
  48. commands, Spaces reduce the amount of
  49. commands that can be entered on each
  50. line. Spaces also take up a byte or so
  51. in memory use, so no spaces help
  52. tighten the programme, and make it
  53. much harder for you and me to see the
  54. different parts. So lets go line by
  55. line, I'll suspect that you have typed
  56. the program in and run it already.
  57.  
  58. Line 1
  59. the rem statement, This tells you what
  60. the programme is about for this
  61. listing, rem is REMARK and can be
  62. anything you like the programme just
  63. ignores the command. Here they are
  64. using Rem to show the title of the
  65. programme. I'm a lazy person and so
  66. don't do it myself, although it is
  67. good practice.
  68.  
  69. Line 2
  70. The print command with the shifted
  71. clear home, the screen is clean up and
  72. putts the cursor at the top left.
  73.  
  74. Line 5
  75. That input statement we covered a
  76. little bit earlier, you can see what
  77. will be written to screen by the text
  78. in quotes. Just like a regular print
  79. statement. Here what ever you type in
  80. will become the variable li. That li
  81. variable pops up again in line 10.
  82.  
  83. Line 10
  84. The random number generator, not much
  85. different to our previous dealing with
  86. this command; Here we don't have a
  87. specific number locked into a formula.
  88. We are using the 0 variable LI.
  89.  
  90. Line 20
  91. The print statement that just writes
  92. to the screen it is ready.
  93.  
  94. Line 30
  95. Input line for you put enter your
  96. number, this becomes the variable gu.
  97.  
  98. Line 35
  99. adds one to the count.
  100.  
  101. Line 40
  102. Takes your number as the variable gu,
  103. compares it to the generated number
  104. and sees if it is greater than the
  105. generated number. Programme commands
  106. to do that read if gu > than nm. Short
  107. and easy for the computer but a whole
  108. new language for us. Second part of
  109. the line is the print statement to
  110. tell you that the number is lower than
  111. your guess.
  112.  
  113. Line 50
  114. This is the reverse of line 40, both
  115. lines end with the programme taking
  116. you back to line 30, where you are
  117. doing the guess and the count of your
  118. guesses is being recorded.
  119.  
  120. Line 60
  121. This is the line that gets to some
  122. people it looks wrong to them, I have
  123. been over this line many a times with
  124. users in our group. There are only
  125. three things that can happen, your
  126. number is higher or lower or right on
  127. Ie you guessed correctly. Line 40 & 50
  128. cover the high and low part. Since the
  129. computer goes from the lowest line
  130. number to the highest <unless
  131. something moves it elsewhere> If line
  132. 40 isn' true, then the program goes to
  133. line 50, which if it isn't true, Well
  134. there is only one other option, that
  135. is you guessed correctly. That is why
  136. this is after the other two
  137. possibilities.
  138.  
  139. Line 65
  140. Prints out text and as you see there
  141. is a break in the text where between
  142. the ; symbols there is the cn
  143. variable. This variable will be
  144. printed out as the number on the
  145. screen. Then more text appears, OK
  146. that print thing after the : symbol
  147. will do that drop down a line down
  148. again trick.
  149.  
  150. Line 70
  151. Goes with the part to play again, Here
  152. the (y/n) is part of the print
  153. statement. As you see in lines 80-100
  154. where the prg is checking to see your
  155. keypress from the KB. Line 80 keeps
  156. the programme stuck at that point,
  157. until there is a keypress, Line 90
  158. gets the y from the keyboard and
  159. starts the game over again. Line 100
  160. is expecting the n and if it doesn't
  161. get it, remember that if a y was typed
  162. we won't be at line 100. So if the
  163. input wasn't an n the Programme goes
  164. back to line 70. Putting up the text
  165. another try. This is an error trap,
  166. just making certain that the user has
  167. only the two listed options.
  168.  
  169. Go ahead and play with the text line
  170. numbers that you insert. Mess about
  171. with screen, border and even the
  172. different text colours. We have a bit
  173. more on this one. And I did say that I
  174. would cover that weird part.
  175.  
  176. Well it is easier to see the programme
  177. functions as you play with it and then
  178. alter it a bit. However the book wants
  179. you to figure out how to set up a
  180. lower limit, now you can fight with
  181. this idea for a while, bash your head
  182. against the wall and the keyboard,
  183. then send me and e-mail that says I
  184. have done this better than the manual.
  185. <Stand by, having a laughing fit at
  186. that idea> Well that is the feeling
  187. every student in the user group had at
  188. this part, You see they want you to go
  189. back in the book to that weird line,
  190. the line that makes no sense as it is
  191. written.
  192.  
  193. Read in the book on page 50 as
  194. follows, and on one line.
  195.  
  196.   NM=INT(LOWERLIMIT+
  197.    (UPPER-LOWER+1)*RND(1))
  198.  
  199. OK we can see from the guessing game
  200. that nm would be the variable, the
  201. rest almost appears to make sense.
  202. You will need to recreate a new input
  203. line, where you ask for the lower
  204. limit; I made this the variable lo. So
  205. now you need to write that random
  206. number generator line, something like
  207. this should work.
  208.  
  209.  NM=INT(LO+(LI-LO+1)*RND(1))
  210.  
  211. A bit more understanding, but maybe if
  212. I substitute the variables into a set
  213. of numbers, you can see it better, I
  214. had to do that for members of the
  215. group.
  216.  
  217.  NM=INT(50(100-50+1)*RND(1))
  218.  
  219. If you want to see how this works out
  220. for you, there is something I haven't
  221. really said yet. You can print out the
  222. value of nm, all you need to do is
  223. type on the screen just after you have
  224. written the above line press return
  225. and dont put this in the programme you
  226. are working upon.
  227.  
  228.  ?NM <press RETURN>
  229.  
  230. The value will be printed right
  231. underneath the nm part you typed,
  232. right cursor up to the random
  233. generator line, press return. Go to
  234. back to the ? nm line and then press
  235. return key, now you get a different
  236. number each time.Right back to the
  237. guessing game programme if you didn't
  238. do it already well it is too late to
  239. save the programme. List it and see if
  240. it is still there and if so what was
  241. damaged, Yeah I am tricking you. <VBG>
  242. I'll let you figure out where to place
  243. the input line for the lower limit, as
  244. to where the random number generator
  245. line should be. <SEG> Next type
  246. programme is small and I would not
  247. include it at this time but there is a
  248. trick on the user from the user book,
  249. and I want you to work with colour,
  250. the Book read as follows.
  251.  
  252. 5 ? "CARE TO TRY YOUR LUCK?"
  253. 10 ?"RED DICE  =";INT(6*RND(1))+1
  254. 20 ?"WHITE DICE  =";INT(6*RND(1))+1
  255. 30 ?"HIT SPACE BAR FOR ANOTHER ROLL":?
  256. 40 GETA$:IFA$=""THEN40
  257. 50 IFA$=CHR$(32)THEN10
  258.  
  259. Right, save for the tightening of the
  260. programme lines, this is the way that
  261. the book has you type it in, So where
  262. are the tricks to you? Well first one
  263. that I saw was using the plural of
  264. DICE rather than the singular term
  265. which is DIE. You know one DIE two
  266. DICE, But that probably isn't the
  267. first thing that caught your eye. Line
  268. 5 is in lower case, that isn't my
  269. programme style or the way I typed out
  270. the line, that is the way it is
  271. written in the book on page 52. I'm
  272. guessing that they wanted to
  273. automatically see it and do the C= and
  274. shift key press to move to lower case,
  275. but type the other lines in upper
  276. case. Did you notice that you aren't
  277. told to "new" the programme? If you
  278. didn't then the programme we typed in
  279. before would still be in the computer
  280. memory, makes the programme run crazy,
  281. that is if it will run at all.
  282.  
  283.  What I want you to do is make the
  284. screen black and the border black,
  285. also I want you to make the words RED
  286. DICE <or for the purist DIE> as red
  287. and the words WHITE DICE as white,
  288. tough assignment isn't it? Well yes it
  289. is for those in the group that didn't
  290. take notes, you have this drivel in a
  291. form that you can use to read back a
  292. bit. on disk or on paper. However that
  293. was a few lessons ago and I will be
  294. here to lend a hand.
  295.  
  296.  Written in lower case it looks like.
  297.  
  298. pO53280,0:pO53281,0
  299.  
  300. These 2 command make the screen and
  301. the border go black. What you need to
  302. do is think where in the programme the
  303. commands should be placed, Hint, the
  304. programme thinks in a straight line,
  305. from low line numbers to higher
  306. numbers.
  307.  
  308. How to make the words in different
  309. colours? Well this is hard, I mean
  310. really hard, after making the quote
  311. you press control key and the number 3
  312. key. Write the words and close the
  313. quote and do the rest of the line.
  314. Same for the words white, although you
  315. make the quote and then press control
  316. key the number 2 for white.
  317.  
  318. Of course if you have some experience
  319. with this sort of thing, you may now
  320. want to try to have the number come
  321. out as a different colour. Thing here
  322. is to see that, what ever colour you
  323. last used will be the colour that will
  324. continue to be used, until you change
  325. it. You can change the colour with the
  326. command of pO646,X where X is a colour
  327. from 0-15. Or PRINT"<control and a
  328. number key" Or PRINT"<c= key and
  329. number key". Actually on a programme
  330. line it would look a little like ?" ".
  331. There will be a symbol between the
  332. quotes, call this for now a colour
  333. code. That will print as the colour
  334. for the text. Have fun playing around,
  335. and feel randy and see what you can do
  336. with reverse video.
  337.  
  338.  New programme and type in
  339.  
  340. 10 ?"<CLEAR/HOME>"
  341. 20 ? CHR$(205.5)+RND(1))
  342. 40 GOTO20
  343.  
  344.  Run that and see what happens on the
  345. screen.
  346.  
  347. If you have a mess of M and N show up,
  348. press shift and C= for upper case.  Ah
  349. there is this weird maze looking thing
  350. that shows up, over and over and over
  351. again. The programme will run until
  352. you press that run/stop key. What is
  353. going on here? That was my question,
  354. all of that stuff on screen for just a
  355. few lines of programming.
  356.  
  357. We have already understood the first
  358. line as the shifted clear home to
  359. clear the screen.
  360. The Last line is the goto statement
  361. that loops the programme back again.
  362. But all the action is created in line
  363. 20. But what is happening there? We
  364. can tell that there is a print
  365. command, we can see that this is going
  366. to print something to do with a sort
  367. of random number generator. A closer
  368. look at the screen shows that the
  369. things printed are the slash lines on
  370. the N and M keys. How doe two symbols
  371. appear with only one statement to
  372. print them? That is how it looks at
  373. first. Lets work things out a bit.
  374.  
  375. CHR$ stands for "character string",
  376. remember I said that there are 256,
  377. that is from 0-255, characters for the
  378. C=. Well each one of them has a
  379. character string, or a number. Real
  380. simple now, what is happening is that
  381. the chr$(205) is a one symbol. There
  382. is no chr$(205.5) the random number
  383. generator is basically making a number
  384. that will be between 205.5 and 206.5.
  385. chr$ will only accept the whole
  386. number. So you have a 50/50 chance of
  387. each of the two chr$ characters
  388. showing up and being printed on the
  389. screen, Rather fast for a 1mcps speed
  390. machine. <VBG>
  391.  
  392.          CONTINUED IN SECTION 2
  393.  
  394.